home *** CD-ROM | disk | FTP | other *** search
- /* system.c
- *
- * Changed to return() on fork failure, added signal()
- * calls. Terrence W. Holm Oct. 1988
- *
- *
- * Adjusted last arg to execl (it should be a NULL pointer not zero)
- * Adjusted type if sig*
- * ++jrb
- */
-
- #include "lib.h"
- #include <stdio.h>
- #include <signal.h>
- #include <sys/wait.h>
-
- int system(cmd)
- _CONST char *cmd;
- {
- int retstat, procid, waitstat;
- #ifdef __STDC__
- void (*sigint)(), (*sigquit)();
- #else
- int (*sigint)(), (*sigquit)();
- #endif
-
- if ( (procid = fork()) == 0) {
- /* Child does an exec of the command. */
- execl( "/bin/sh", "sh", "-c", cmd, (char *)NULL );
- exit( 127 );
- }
-
- /* Check to see if fork failed. */
- if (procid < 0) return( 127 << 8 );
-
- sigint = signal( SIGINT, SIG_IGN );
- sigquit = signal( SIGQUIT, SIG_IGN );
-
- while ( (waitstat = wait(&retstat)) != procid && waitstat != -1 ) ;
- if (waitstat == -1) retstat = -1;
-
- signal( SIGINT, sigint );
- signal( SIGQUIT, sigquit );
-
- return(retstat);
- }
-